#ifndef _game_h_included_
#define _game_h_included_
#include <d3dx9.h>
#include <d3d9.h>
#include "DXUtil.h"
#include "Camera.h"
#include "Model.h"
#include "Light.h"
#include "Mesh.h"
#include "Primitive.h"
#include <vector>
#include <sstream>
#include "FractalTree.h"
#include "NoiseSphere.h"

#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h> // DirectX/Direct Input

#include "Ray.h"
using namespace std;

class FractalTree;


//The basis for the scene.
//Controls updates, drawing and removal or models.
class Game
{
	IDirect3DSurface9 *backBuffer;

	//Models
	vector<Model*> mModels;
	
	vector<LIGHT*> mLights;
	//Lights: Support enabled for multiple light sources.  
	//vector<LIGTH*> mLights;

	D3DXCOLOR ambientLight;
	float ambientStrength;

	//Camera:  only one camera is supported 
	//			but more could be added;
	

	//The identity Matrix
	D3DXMATRIX mIdentity;

	void AverageColors(D3DXCOLOR* output, D3DXCOLOR* color[], int n);

	int frameCount;

	FractalTree* ft;

	//Trace Ray vals
	D3DXMATRIX identityMatrix;
	D3DVIEWPORT9 viewport;


public:
	NoiseSphere* mIntersects;
	int mIntSize;
	Camera* mCamera;
	NoiseSphere* mObjectList;
	int mListSize;
	string infile;
	LPDIRECT3D9 d3d;    // the pointer to our Direct3D interface
	LPDIRECT3DDEVICE9 d3ddev; 

D3DXCOLOR* image;
	//create the ray
	RAY calcRay(Camera &cam, int x,int y,D3DXVECTOR3 &p1,D3DXVECTOR3 &p2);

	//D3DXCOLOR* getColor(Camera &cam, RAY ray, int depth);
	D3DXCOLOR* getHypertextureColor(Camera &cam, RAY ray);

	//Creates the scene
	void Initialize();

	//All scene specific ini's go here
	void IniScene();
	
	void LoadContent();
	//Updates the scene
	void Update( double pElapsedTime); 
	//Draws the scene
	void Draw();

	//Releases all data for the scene.
	void Release();

	D3DVECTOR* DetermineEllipseTangent(D3DVECTOR* circle,D3DVECTOR* point );
	void initD3D(HWND hWnd);

	void Present();
	void ScreenShot();
};
#endif
